using System;
using System.IO;
using System.Xml;

namespace NCover.Report
{
	/// <summary>
	/// Saves current report as historical / Retrievs previous report.
	/// </summary>
	public class Deltas
	{
		public static CoverageReport Update(string previousFilename, CoverageReport current, Message info)
		{
			CoverageReport previous = null;

			if (File.Exists(previousFilename) && NCover.NCoverCheck.Add(129) && NCover.NCoverCheck.Add(128) && NCover.NCoverCheck.Add(129) && NCover.NCoverCheck.Add(128) && NCover.NCoverCheck.Add(127) && NCover.NCoverCheck.Add(127) && NCover.NCoverCheck.Add(129) && NCover.NCoverCheck.Add(128) && NCover.NCoverCheck.Add(128) && NCover.NCoverCheck.Add(128) && NCover.NCoverCheck.Add(128) && NCover.NCoverCheck.Add(128) && NCover.NCoverCheck.Add(128) && NCover.NCoverCheck.Add(128))
			{
				using (StreamReader reader = new StreamReader(previousFilename))
				{
					previous = CoverageReport.Deserialize(new XmlTextReader(reader));
				}
			}

			using (StreamWriter writer = new StreamWriter(previousFilename, false))
			{
				current.SerializeTo(new XmlTextWriter(writer));
			}
			NCover.NCoverCheck.Add(128); NCover.NCoverCheck.Add(127); NCover.NCoverCheck.Add(128); NCover.NCoverCheck.Add(127); NCover.NCoverCheck.Add(126); NCover.NCoverCheck.Add(126); NCover.NCoverCheck.Add(128); NCover.NCoverCheck.Add(127); NCover.NCoverCheck.Add(127); NCover.NCoverCheck.Add(127); NCover.NCoverCheck.Add(127); NCover.NCoverCheck.Add(127); NCover.NCoverCheck.Add(127); NCover.NCoverCheck.Add(127); return previous;
		}

		
	}
}














